package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.chatroom.Message
import ink.metoo.auto.fishpi.chatroom.RedPacket

object CommandFactory : Command {

    private val commands = mutableListOf<Command>()

    private fun registerCommand(command: Command) {
        commands.add(command)
    }

    init {
        registerCommand(SendRedPacketCommand(RedPacket.Type.RANDOM))
        registerCommand(SendRedPacketCommand(RedPacket.Type.AVERAGE))
        registerCommand(SendRedPacketCommand(RedPacket.Type.HEARTBEAT))
        registerCommand(SendSpecifyRedPacketCommand())
        registerCommand(SendRockPaperScissorsCommand())
        registerCommand(SendChequeCommand())
        registerCommand(SendChequeCommand.SendGetChequeCommand())
        // registerCommand(SetSettingCommand())
        registerCommand(QuteMessageCommand())
        registerCommand(RevokeMessageCommand())
        registerCommand(RepeatMessageCommand())
        registerCommand(TopicCommand())
        registerCommand(ViewCommand())
        registerCommand(GuessGuessingRiddleCommand())
        registerCommand(CamouflageMusicCommand())
        registerCommand(QueryWeatherCommand())
    }

    fun handle(message: Message) {
        commands.forEach {
            if (it.isMatch(message)) {
                it.execute(message)
            }
        }
    }

    override val commandText: String = ""

    override fun isMatch(message: Message): Boolean = true

    override fun execute(message: Message) = handle(message)

    val commandSelfTexts = commands
        .filter { it.commandTypes.contains(Command.Type.SELF_CLIENT) }
        .map { it.commandText }

}